<template>
  <div class="mainin">
    <div class="inputclass">
      <el-input
        v-model="movieNameFor"
        placeholder="请输入要查询的电影"
        style="width: 200px"
      ></el-input>
      <el-button type="primary" round @click="search()">搜索</el-button>
      <span v-show="msgShow">{{ msg }}</span>
      <el-button
        plain
        style="display: inline-block; margin-left: 100px"
        @click="searchPerson()"
        >个人资料</el-button
      >
    </div>
    <div class="mainclass" style="margin-top: 10px">
      <div
        class="flexclass"
        v-for="movie in movies"
        :key="movie.index"
        @click="searchByPage(movie.movieName)"
      >
        <!-- movie.moviePicture -->
        <img :src="movie.moviePicture" style="width: 100%; height: 99%" />
        <h5 style="display: inline">
          {{ movie.movieName }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;评分：{{
            movie.movieScore
          }}
        </h5>
      </div>
    </div>
    <el-dialog title="个人信息" :visible.sync="dialogVisible" width="30%">
      <el-form status-icon label-width="100px" class="demo-ruleForm">
        <el-form-item label="账号">
          <el-input
            type="text"
            v-model="person.userAccount"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            type="password"
            v-model="person.userPassword"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            type="date"
            v-model="person.userBirthday"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            type="text"
            v-model="person.userEmail"
            autocomplete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updatePerson()">修 改</el-button>
      </span>
    </el-dialog>

    <el-dialog title="电影信息" :visible.sync="movieVisibl" width="50%">
      <el-form>
        <el-form-item label="电影名称:">
          <el-input
            type="text"
            v-model="movie.movieName"
            :disabled="true"
            style="width: 80%"
          ></el-input>
        </el-form-item>
        <el-form-item label="电影主演:">
          <el-input
            type="text"
            v-model="movie.movieMainPerson"
            :disabled="true"
            style="width: 80%"
          ></el-input>
        </el-form-item>
        <el-form-item label="电影评分:">
          <el-input
            type="text"
            v-model="movie.movieScore"
            :disabled="true"
            style="width: 80%"
          ></el-input>
        </el-form-item>
        <el-form-item label="电影类型:">
          <el-input
            type="text"
            v-model="movie.movieType"
            :disabled="true"
            style="width: 80%"
          ></el-input>
        </el-form-item>
        <el-form-item label="上映时间:">
          <el-input
            type="date"
            v-model="movie.movieShowDate"
            :disabled="true"
            style="width: 80%"
          ></el-input>
        </el-form-item>
        <el-form-item label="电影时长:">
          <el-input
            type="text"
            v-model="movie.movieDuration"
            :disabled="true"
            style="width: 80%"
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="movieVisibl = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      movieNameFor: "",
      movies: [],
      dialogVisible: false,
      person: {
        userAccount: "",
        userPassword: "",
        userBirthday: "",
        userEmail: "",
      },
      movie: {
        movieName: "",
        movieMainPerson: "",
        movieScore: "",
        movieType: "",
        movieShowDate: "",
        movieDuration: "",
      },
      movieVisibl: false,
      msg: "查无此电影",
      msgShow: false,
    };
  },
  methods: {
    async searchByPage(nameBypage) {
      const { data: res } = await this.$axios({
        method: "post",
        url: "/movies/search",
        data: {
          movieName: nameBypage,
        },
      });
      this.msgShow = false;
      this.movie = res.data;
      this.movieVisibl = true;
    },

    async search() {
      const { data: res } = await this.$axios({
        method: "post",
        url: "/movies/search",
        data: {
          movieName: this.movieNameFor,
        },
      });
      if (res.data !== null) {
        this.movie = res.data;
        this.movieVisibl = true;
        this.msgShow = false;
      } else {
        this.msgShow = true;
      }
    },
    async searchPerson(a) {
      const { data: res } = await this.$axios({
        method: "post",
        url: "/user/login",
        data: {
          userName: this.$store.state.account,
          userPassword: this.$store.state.password,
        },
      });
      this.person.userAccount = res.data.userName;
      this.person.userPassword = res.data.userPassword;
      this.person.userBirthday = res.data.userBirthday;
      this.person.userEmail = res.data.userEmail;
      this.dialogVisible = true;
    },
    async updatePerson() {
      const { data: res } = await this.$axios({
        method: "post",
        url: "/user/update",
        data: {
          userName: this.person.userAccount,
          userPassword: this.person.userPassword,
          userBirthday: this.person.userBirthday,
          userEmail: this.person.userEmail,
        },
      });
      this.dialogVisible = false;
    },
  },
  async created() {
    const { data: res } = await this.$axios({
      method: "get",
      url: "/movies/page",
    });
    this.movies = res.data.records;
    this.movies[0].moviePicture = require("../assets/xskdjs.webp");
    this.movies[1].moviePicture = require("../assets/bwbj.webp");
    this.movies[2].moviePicture = require("../assets/agzz.webp");
    this.movies[3].moviePicture = require("../assets/ttnkh.webp");
    this.movies[4].moviePicture = require("../assets/zgssbtl.webp");
    this.movies[5].moviePicture = require("../assets/mlrs.webp");
    this.movies[6].moviePicture = require("../assets/qyqx.webp");
    this.movies[7].moviePicture = require("../assets/cmdsj.webp");
  },
};
</script>

<style scoped>
.mainin {
  margin: auto;
  margin-top: 50px;
  height: 600px;
  width: 90%;
}
.inputclass {
  width: 100%;
  margin: auto;
}
.mainclass {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  width: 80%;
  margin: auto;
  height: 550px;
}
.flexclass {
  background-color: #fff;
  width: 220px;
  height: 250px;
}
</style>